package com.lin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lin.entity.GroupInformation;
import com.lin.entity.ProjectDetail;
import com.lin.entity.Talents;
import com.lin.mapper.TalentsMapper;
import com.lin.service.GroupInformationService;
import com.lin.service.ProjectDetailService;
import com.lin.service.TalentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 林伟鸿
 * @since 2022-04-16
 */
@Service
public class TalentsServiceImpl extends ServiceImpl<TalentsMapper, Talents> implements TalentsService {

    @Resource
    GroupInformationService groupInformationService;

    @Resource
    ProjectDetailService projectDetailService;

    @Override
    public List<Map<String, Object>> getMyProjects(int currentUserUid) {
        List<GroupInformation> myGroupList = groupInformationService.list(new QueryWrapper<GroupInformation>()
                .eq("master_id", currentUserUid)
                .or().eq("memberOneId", currentUserUid).or().eq("memberTwoId", currentUserUid)
                .or().eq("memberThreeId", currentUserUid)
                .or().eq("memberFourId", currentUserUid));
        List<ProjectDetail> projectDetailList = new ArrayList<>();
        myGroupList.forEach(g -> {
            Integer groupId = g.getGroupId();
            ProjectDetail projectDetail = projectDetailService.getOne(new QueryWrapper<ProjectDetail>().eq("group_id", groupId));
            projectDetailList.add(projectDetail);
        });
        List<Map<String, Object>> res = new ArrayList<>();
        Map<String, Object> map = null;
        for (ProjectDetail projectDetail : projectDetailList) {
            map = new HashMap<>();
            map.put("projectId", projectDetail.getProjectId());
            map.put("projectName", projectDetail.getProjectName());
            res.add(map);
        }
        return res;
    }
}
